﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using FlashTools;
using System.Net;
using System.Text;
using QzEbook.Common;

public partial class swf2gif : System.Web.UI.Page
{
    private string swfVar;
    private string swfPath;
    private string savePath;
    private int width, height;
    private int frames;

    protected void Page_Load(object sender, EventArgs e)
    {
        string rawUrl=Request.RawUrl;
        string swfurl=Request["swf"] as string;
       
        if (string.IsNullOrEmpty(swfurl)||swfurl.ToLower().IndexOf(".swf")<0)
        {
            Response.Write("请输入swf路径");
            Response.End();
        }
        
        string[] list=swfurl.Split('?');
        swfPath=list[0];

        int index=rawUrl.IndexOf(swfPath);
        swfVar = rawUrl.Substring(index).Replace(swfPath+"?","");
        swfVar = Server.UrlPathEncode(swfVar);
        savePath = Server.MapPath(Config.UserBookSavePath + "webswf.swf");


        WebClient webClient = new WebClient();
        
        webClient.DownloadFile(swfPath, savePath);
        webClient.Dispose();
        SWFFile swf = new SWFFile(savePath);

        frames = swf.FrameCount;

        height = (int)(swf.FrameHeight/100);
        Response.Write(swfVar + "<br/>");
        Response.Write(swf.FileName+ "<br/>");
        Response.Write(swf.FrameRate+"<br/>");
        Response.Write(swf.FrameCount);
        swf.Close();
        
    }

    public void bulidSWF()
    {
        Session.Remove("swf2images");
        Session.Remove("swfAutoId");
        Session["frameCount"] = frames;
        StringBuilder sb = new StringBuilder();

        sb.Append("<script language=\"javascript\" type=\"text/javascript\">");
        sb.AppendLine();
        sb.AppendLine("var crlnet='crlnet'");
        sb.AppendFormat("var so = new SWFObject('main.swf?swf={0}&frameCount={1}',crlnet , '100%', '300', '8', '', true);", Config.UserBookSavePath + "webswf.swf?"+Server.UrlEncode(swfVar), frames);
        sb.AppendLine();

       // sb.AppendFormat("so.addParam(\"FlashVars\", \"swf={0}\");",swfPath);
        //sb.AppendLine();
        sb.AppendLine("so.setAttribute('xiRedirectUrl', window.location);");
        sb.AppendLine("so.write('flashcontent');");
        sb.Append("</script>");

        Response.Write(sb.ToString());
    }

}
